package com.ruoyi.st.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.st.domain.StTicketInfo;
import com.ruoyi.st.service.IStTicketInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售票信息 (st_ticket_info)Controller
 * 
 * @author ruoyi
 * @date 2024-11-06
 */

@Slf4j
@RestController
@RequestMapping("/st/ticketInfo")
public class StTicketInfoController extends BaseController
{
    @Autowired
    private IStTicketInfoService stTicketInfoService;

    /**
     * 查询售票信息 (st_ticket_info)列表
     */
    @PreAuthorize("@ss.hasPermi('st:ticketInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(StTicketInfo stTicketInfo)
    {
        startPage();
        List<StTicketInfo> list = stTicketInfoService.selectStTicketInfoList(stTicketInfo);
        return getDataTable(list);
    }

    /**
     * 导出售票信息 (st_ticket_info)列表
     */
    @PreAuthorize("@ss.hasPermi('st:ticketInfo:export')")
    @Log(title = "售票信息 (st_ticket_info)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StTicketInfo stTicketInfo)
    {
        List<StTicketInfo> list = stTicketInfoService.selectStTicketInfoList(stTicketInfo);
        ExcelUtil<StTicketInfo> util = new ExcelUtil<StTicketInfo>(StTicketInfo.class);
        util.exportExcel(response, list, "售票信息 (st_ticket_info)数据");
    }

    /**
     * 获取售票信息 (st_ticket_info)详细信息
     */
    @PreAuthorize("@ss.hasPermi('st:ticketInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stTicketInfoService.selectStTicketInfoById(id));
    }

    /**
     * 根据演出详情ID获取指定的购票信息
     */
    @GetMapping("/buyTicketDetail")
    public AjaxResult buyTicketDetail(@RequestParam Long performanceId){
        log.debug("根据演出详情ID获取指定购票信息={}",performanceId);

        return success(stTicketInfoService.selectStTicketInfoByPerformanceId(performanceId));
    }

    /**
     * 新增售票信息 (st_ticket_info)
     */
    @PreAuthorize("@ss.hasPermi('st:ticketInfo:add')")
    @Log(title = "售票信息 (st_ticket_info)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StTicketInfo stTicketInfo)
    {
        return toAjax(stTicketInfoService.insertStTicketInfo(stTicketInfo));
    }

    /**
     * 修改售票信息 (st_ticket_info)
     */
    @PreAuthorize("@ss.hasPermi('st:ticketInfo:edit')")
    @Log(title = "售票信息 (st_ticket_info)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StTicketInfo stTicketInfo)
    {
        return toAjax(stTicketInfoService.updateStTicketInfo(stTicketInfo));
    }

    /**
     * 删除售票信息 (st_ticket_info)
     */
    @PreAuthorize("@ss.hasPermi('st:ticketInfo:remove')")
    @Log(title = "售票信息 (st_ticket_info)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stTicketInfoService.deleteStTicketInfoByIds(ids));
    }
}
